package descentFly.jiglib
{
	import flash.geom.Matrix3D;
	import flash.geom.Vector3D;
	
	import jiglib.physics.RigidBody;

	public class utils {
		public static function localToGlobal(obj: RigidBody, v: Vector3D): Vector3D {
			var mat: Matrix3D = obj.skin.transform.clone();
			mat.invert();
			return mat.transformVector(v);
		}
		
		public static function globalToLocal(obj: RigidBody, v: Vector3D): Vector3D {
			return obj.skin.transform.transformVector(v);
		}
		
		public static function asVector(obj: Object): Vector3D {
			if (obj is Vector3D) return obj as Vector3D;
			else if ((obj is Array) || (obj is Vector.<Number>)) return new Vector3D(obj[0], obj[1], obj[2]);
			return null;
		}
	}
}